package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.TemplateMarket;
import com.xjgzinfo.usdp.service.EvaluationDataService;
import com.xjgzinfo.usdp.service.dto.EvaluationDataDTO;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link EvaluationDataResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class EvaluationDataResourceIT {

    private static final Long DEFAULT_TEMPLATE_ID = 1L;
    private static final Long UPDATED_TEMPLATE_ID = 2L;
    private static final Long SMALLER_TEMPLATE_ID = 1L - 1L;

    private static final String DEFAULT_ORIGIN_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_ORIGIN_TYPE = "BBBBBBBBBB";

    private static final Double DEFAULT_TOTAL_SCORE = 1D;
    private static final Double UPDATED_TOTAL_SCORE = 2D;
    private static final Double SMALLER_TOTAL_SCORE = 1D - 1D;

    private static final Double DEFAULT_APPLAUSE_RATE = 1D;
    private static final Double UPDATED_APPLAUSE_RATE = 2D;
    private static final Double SMALLER_APPLAUSE_RATE = 1D - 1D;

    private static final Instant DEFAULT_UPDATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_UPDATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    @Autowired
    private EvaluationDataRepository evaluationDataRepository;

    @Autowired
    private EvaluationDataMapper evaluationDataMapper;

    @Autowired
    private EvaluationDataService evaluationDataService;

    @Autowired
    private EvaluationDataQueryService evaluationDataQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restEvaluationDataMockMvc;

    private EvaluationData evaluationData;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static EvaluationData createEntity(EntityManager em) {
        EvaluationData evaluationData = new EvaluationData()
            .templateId(DEFAULT_TEMPLATE_ID)
            .originType(DEFAULT_ORIGIN_TYPE)
            .totalScore(DEFAULT_TOTAL_SCORE)
            .applauseRate(DEFAULT_APPLAUSE_RATE)
            .updateTime(DEFAULT_UPDATE_TIME);
        return evaluationData;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static EvaluationData createUpdatedEntity(EntityManager em) {
        EvaluationData evaluationData = new EvaluationData()
            .templateId(UPDATED_TEMPLATE_ID)
            .originType(UPDATED_ORIGIN_TYPE)
            .totalScore(UPDATED_TOTAL_SCORE)
            .applauseRate(UPDATED_APPLAUSE_RATE)
            .updateTime(UPDATED_UPDATE_TIME);
        return evaluationData;
    }

    @BeforeEach
    public void initTest() {
        evaluationData = createEntity(em);
    }

    @Test
    @Transactional
    public void createEvaluationData() throws Exception {
        int databaseSizeBeforeCreate = evaluationDataRepository.findAll().size();
        // Create the EvaluationData
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(evaluationData);
        restEvaluationDataMockMvc.perform(post("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isCreated());

        // Validate the EvaluationData in the database
        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeCreate + 1);
        EvaluationData testEvaluationData = evaluationDataList.get(evaluationDataList.size() - 1);
        assertThat(testEvaluationData.getTemplateId()).isEqualTo(DEFAULT_TEMPLATE_ID);
        assertThat(testEvaluationData.getOriginType()).isEqualTo(DEFAULT_ORIGIN_TYPE);
        assertThat(testEvaluationData.getTotalScore()).isEqualTo(DEFAULT_TOTAL_SCORE);
        assertThat(testEvaluationData.getApplauseRate()).isEqualTo(DEFAULT_APPLAUSE_RATE);
        assertThat(testEvaluationData.getUpdateTime()).isEqualTo(DEFAULT_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void createEvaluationDataWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = evaluationDataRepository.findAll().size();

        // Create the EvaluationData with an existing ID
        evaluationData.setId(1L);
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(evaluationData);

        // An entity with an existing ID cannot be created, so this API call must fail
        restEvaluationDataMockMvc.perform(post("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isBadRequest());

        // Validate the EvaluationData in the database
        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkTemplateIdIsRequired() throws Exception {
        int databaseSizeBeforeTest = evaluationDataRepository.findAll().size();
        // set the field null
        evaluationData.setTemplateId(null);

        // Create the EvaluationData, which fails.
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(evaluationData);


        restEvaluationDataMockMvc.perform(post("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isBadRequest());

        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkOriginTypeIsRequired() throws Exception {
        int databaseSizeBeforeTest = evaluationDataRepository.findAll().size();
        // set the field null
        evaluationData.setOriginType(null);

        // Create the EvaluationData, which fails.
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(evaluationData);


        restEvaluationDataMockMvc.perform(post("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isBadRequest());

        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkTotalScoreIsRequired() throws Exception {
        int databaseSizeBeforeTest = evaluationDataRepository.findAll().size();
        // set the field null
        evaluationData.setTotalScore(null);

        // Create the EvaluationData, which fails.
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(evaluationData);


        restEvaluationDataMockMvc.perform(post("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isBadRequest());

        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllEvaluationData() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(evaluationData.getId().intValue())))
            .andExpect(jsonPath("$.[*].templateId").value(hasItem(DEFAULT_TEMPLATE_ID.intValue())))
            .andExpect(jsonPath("$.[*].originType").value(hasItem(DEFAULT_ORIGIN_TYPE)))
            .andExpect(jsonPath("$.[*].totalScore").value(hasItem(DEFAULT_TOTAL_SCORE.doubleValue())))
            .andExpect(jsonPath("$.[*].applauseRate").value(hasItem(DEFAULT_APPLAUSE_RATE.doubleValue())))
            .andExpect(jsonPath("$.[*].updateTime").value(hasItem(DEFAULT_UPDATE_TIME.toString())));
    }
    
    @Test
    @Transactional
    public void getEvaluationData() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get the evaluationData
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data/{id}", evaluationData.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(evaluationData.getId().intValue()))
            .andExpect(jsonPath("$.templateId").value(DEFAULT_TEMPLATE_ID.intValue()))
            .andExpect(jsonPath("$.originType").value(DEFAULT_ORIGIN_TYPE))
            .andExpect(jsonPath("$.totalScore").value(DEFAULT_TOTAL_SCORE.doubleValue()))
            .andExpect(jsonPath("$.applauseRate").value(DEFAULT_APPLAUSE_RATE.doubleValue()))
            .andExpect(jsonPath("$.updateTime").value(DEFAULT_UPDATE_TIME.toString()));
    }


    @Test
    @Transactional
    public void getEvaluationDataByIdFiltering() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        Long id = evaluationData.getId();

        defaultEvaluationDataShouldBeFound("id.equals=" + id);
        defaultEvaluationDataShouldNotBeFound("id.notEquals=" + id);

        defaultEvaluationDataShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultEvaluationDataShouldNotBeFound("id.greaterThan=" + id);

        defaultEvaluationDataShouldBeFound("id.lessThanOrEqual=" + id);
        defaultEvaluationDataShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId equals to DEFAULT_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.equals=" + DEFAULT_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId equals to UPDATED_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.equals=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId not equals to DEFAULT_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.notEquals=" + DEFAULT_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId not equals to UPDATED_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.notEquals=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsInShouldWork() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId in DEFAULT_TEMPLATE_ID or UPDATED_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.in=" + DEFAULT_TEMPLATE_ID + "," + UPDATED_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId equals to UPDATED_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.in=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId is not null
        defaultEvaluationDataShouldBeFound("templateId.specified=true");

        // Get all the evaluationDataList where templateId is null
        defaultEvaluationDataShouldNotBeFound("templateId.specified=false");
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId is greater than or equal to DEFAULT_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.greaterThanOrEqual=" + DEFAULT_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId is greater than or equal to UPDATED_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.greaterThanOrEqual=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId is less than or equal to DEFAULT_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.lessThanOrEqual=" + DEFAULT_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId is less than or equal to SMALLER_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.lessThanOrEqual=" + SMALLER_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsLessThanSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId is less than DEFAULT_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.lessThan=" + DEFAULT_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId is less than UPDATED_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.lessThan=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where templateId is greater than DEFAULT_TEMPLATE_ID
        defaultEvaluationDataShouldNotBeFound("templateId.greaterThan=" + DEFAULT_TEMPLATE_ID);

        // Get all the evaluationDataList where templateId is greater than SMALLER_TEMPLATE_ID
        defaultEvaluationDataShouldBeFound("templateId.greaterThan=" + SMALLER_TEMPLATE_ID);
    }


    @Test
    @Transactional
    public void getAllEvaluationDataByOriginTypeIsEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where originType equals to DEFAULT_ORIGIN_TYPE
        defaultEvaluationDataShouldBeFound("originType.equals=" + DEFAULT_ORIGIN_TYPE);

        // Get all the evaluationDataList where originType equals to UPDATED_ORIGIN_TYPE
        defaultEvaluationDataShouldNotBeFound("originType.equals=" + UPDATED_ORIGIN_TYPE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByOriginTypeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where originType not equals to DEFAULT_ORIGIN_TYPE
        defaultEvaluationDataShouldNotBeFound("originType.notEquals=" + DEFAULT_ORIGIN_TYPE);

        // Get all the evaluationDataList where originType not equals to UPDATED_ORIGIN_TYPE
        defaultEvaluationDataShouldBeFound("originType.notEquals=" + UPDATED_ORIGIN_TYPE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByOriginTypeIsInShouldWork() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where originType in DEFAULT_ORIGIN_TYPE or UPDATED_ORIGIN_TYPE
        defaultEvaluationDataShouldBeFound("originType.in=" + DEFAULT_ORIGIN_TYPE + "," + UPDATED_ORIGIN_TYPE);

        // Get all the evaluationDataList where originType equals to UPDATED_ORIGIN_TYPE
        defaultEvaluationDataShouldNotBeFound("originType.in=" + UPDATED_ORIGIN_TYPE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByOriginTypeIsNullOrNotNull() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where originType is not null
        defaultEvaluationDataShouldBeFound("originType.specified=true");

        // Get all the evaluationDataList where originType is null
        defaultEvaluationDataShouldNotBeFound("originType.specified=false");
    }
                @Test
    @Transactional
    public void getAllEvaluationDataByOriginTypeContainsSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where originType contains DEFAULT_ORIGIN_TYPE
        defaultEvaluationDataShouldBeFound("originType.contains=" + DEFAULT_ORIGIN_TYPE);

        // Get all the evaluationDataList where originType contains UPDATED_ORIGIN_TYPE
        defaultEvaluationDataShouldNotBeFound("originType.contains=" + UPDATED_ORIGIN_TYPE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByOriginTypeNotContainsSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where originType does not contain DEFAULT_ORIGIN_TYPE
        defaultEvaluationDataShouldNotBeFound("originType.doesNotContain=" + DEFAULT_ORIGIN_TYPE);

        // Get all the evaluationDataList where originType does not contain UPDATED_ORIGIN_TYPE
        defaultEvaluationDataShouldBeFound("originType.doesNotContain=" + UPDATED_ORIGIN_TYPE);
    }


    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore equals to DEFAULT_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.equals=" + DEFAULT_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore equals to UPDATED_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.equals=" + UPDATED_TOTAL_SCORE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsNotEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore not equals to DEFAULT_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.notEquals=" + DEFAULT_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore not equals to UPDATED_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.notEquals=" + UPDATED_TOTAL_SCORE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsInShouldWork() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore in DEFAULT_TOTAL_SCORE or UPDATED_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.in=" + DEFAULT_TOTAL_SCORE + "," + UPDATED_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore equals to UPDATED_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.in=" + UPDATED_TOTAL_SCORE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsNullOrNotNull() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore is not null
        defaultEvaluationDataShouldBeFound("totalScore.specified=true");

        // Get all the evaluationDataList where totalScore is null
        defaultEvaluationDataShouldNotBeFound("totalScore.specified=false");
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore is greater than or equal to DEFAULT_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.greaterThanOrEqual=" + DEFAULT_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore is greater than or equal to UPDATED_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.greaterThanOrEqual=" + UPDATED_TOTAL_SCORE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore is less than or equal to DEFAULT_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.lessThanOrEqual=" + DEFAULT_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore is less than or equal to SMALLER_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.lessThanOrEqual=" + SMALLER_TOTAL_SCORE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsLessThanSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore is less than DEFAULT_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.lessThan=" + DEFAULT_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore is less than UPDATED_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.lessThan=" + UPDATED_TOTAL_SCORE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTotalScoreIsGreaterThanSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where totalScore is greater than DEFAULT_TOTAL_SCORE
        defaultEvaluationDataShouldNotBeFound("totalScore.greaterThan=" + DEFAULT_TOTAL_SCORE);

        // Get all the evaluationDataList where totalScore is greater than SMALLER_TOTAL_SCORE
        defaultEvaluationDataShouldBeFound("totalScore.greaterThan=" + SMALLER_TOTAL_SCORE);
    }


    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate equals to DEFAULT_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.equals=" + DEFAULT_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate equals to UPDATED_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.equals=" + UPDATED_APPLAUSE_RATE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsNotEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate not equals to DEFAULT_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.notEquals=" + DEFAULT_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate not equals to UPDATED_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.notEquals=" + UPDATED_APPLAUSE_RATE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsInShouldWork() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate in DEFAULT_APPLAUSE_RATE or UPDATED_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.in=" + DEFAULT_APPLAUSE_RATE + "," + UPDATED_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate equals to UPDATED_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.in=" + UPDATED_APPLAUSE_RATE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsNullOrNotNull() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate is not null
        defaultEvaluationDataShouldBeFound("applauseRate.specified=true");

        // Get all the evaluationDataList where applauseRate is null
        defaultEvaluationDataShouldNotBeFound("applauseRate.specified=false");
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate is greater than or equal to DEFAULT_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.greaterThanOrEqual=" + DEFAULT_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate is greater than or equal to UPDATED_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.greaterThanOrEqual=" + UPDATED_APPLAUSE_RATE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate is less than or equal to DEFAULT_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.lessThanOrEqual=" + DEFAULT_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate is less than or equal to SMALLER_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.lessThanOrEqual=" + SMALLER_APPLAUSE_RATE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsLessThanSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate is less than DEFAULT_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.lessThan=" + DEFAULT_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate is less than UPDATED_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.lessThan=" + UPDATED_APPLAUSE_RATE);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByApplauseRateIsGreaterThanSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where applauseRate is greater than DEFAULT_APPLAUSE_RATE
        defaultEvaluationDataShouldNotBeFound("applauseRate.greaterThan=" + DEFAULT_APPLAUSE_RATE);

        // Get all the evaluationDataList where applauseRate is greater than SMALLER_APPLAUSE_RATE
        defaultEvaluationDataShouldBeFound("applauseRate.greaterThan=" + SMALLER_APPLAUSE_RATE);
    }


    @Test
    @Transactional
    public void getAllEvaluationDataByUpdateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where updateTime equals to DEFAULT_UPDATE_TIME
        defaultEvaluationDataShouldBeFound("updateTime.equals=" + DEFAULT_UPDATE_TIME);

        // Get all the evaluationDataList where updateTime equals to UPDATED_UPDATE_TIME
        defaultEvaluationDataShouldNotBeFound("updateTime.equals=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByUpdateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where updateTime not equals to DEFAULT_UPDATE_TIME
        defaultEvaluationDataShouldNotBeFound("updateTime.notEquals=" + DEFAULT_UPDATE_TIME);

        // Get all the evaluationDataList where updateTime not equals to UPDATED_UPDATE_TIME
        defaultEvaluationDataShouldBeFound("updateTime.notEquals=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByUpdateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where updateTime in DEFAULT_UPDATE_TIME or UPDATED_UPDATE_TIME
        defaultEvaluationDataShouldBeFound("updateTime.in=" + DEFAULT_UPDATE_TIME + "," + UPDATED_UPDATE_TIME);

        // Get all the evaluationDataList where updateTime equals to UPDATED_UPDATE_TIME
        defaultEvaluationDataShouldNotBeFound("updateTime.in=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByUpdateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        // Get all the evaluationDataList where updateTime is not null
        defaultEvaluationDataShouldBeFound("updateTime.specified=true");

        // Get all the evaluationDataList where updateTime is null
        defaultEvaluationDataShouldNotBeFound("updateTime.specified=false");
    }

    @Test
    @Transactional
    public void getAllEvaluationDataByTemplateMarketIsEqualToSomething() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);
        TemplateMarket templateMarket = TemplateMarketResourceIT.createEntity(em);
        em.persist(templateMarket);
        em.flush();
        evaluationData.setTemplateMarket(templateMarket);
        templateMarket.setEvaluationData(evaluationData);
        evaluationDataRepository.saveAndFlush(evaluationData);
        Long templateMarketId = templateMarket.getId();

        // Get all the evaluationDataList where templateMarket equals to templateMarketId
        defaultEvaluationDataShouldBeFound("templateMarketId.equals=" + templateMarketId);

        // Get all the evaluationDataList where templateMarket equals to templateMarketId + 1
        defaultEvaluationDataShouldNotBeFound("templateMarketId.equals=" + (templateMarketId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultEvaluationDataShouldBeFound(String filter) throws Exception {
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(evaluationData.getId().intValue())))
            .andExpect(jsonPath("$.[*].templateId").value(hasItem(DEFAULT_TEMPLATE_ID.intValue())))
            .andExpect(jsonPath("$.[*].originType").value(hasItem(DEFAULT_ORIGIN_TYPE)))
            .andExpect(jsonPath("$.[*].totalScore").value(hasItem(DEFAULT_TOTAL_SCORE.doubleValue())))
            .andExpect(jsonPath("$.[*].applauseRate").value(hasItem(DEFAULT_APPLAUSE_RATE.doubleValue())))
            .andExpect(jsonPath("$.[*].updateTime").value(hasItem(DEFAULT_UPDATE_TIME.toString())));

        // Check, that the count call also returns 1
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultEvaluationDataShouldNotBeFound(String filter) throws Exception {
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingEvaluationData() throws Exception {
        // Get the evaluationData
        restEvaluationDataMockMvc.perform(get("/api/evaluation-data/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateEvaluationData() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        int databaseSizeBeforeUpdate = evaluationDataRepository.findAll().size();

        // Update the evaluationData
        EvaluationData updatedEvaluationData = evaluationDataRepository.findById(evaluationData.getId()).get();
        // Disconnect from session so that the updates on updatedEvaluationData are not directly saved in db
        em.detach(updatedEvaluationData);
        updatedEvaluationData
            .templateId(UPDATED_TEMPLATE_ID)
            .originType(UPDATED_ORIGIN_TYPE)
            .totalScore(UPDATED_TOTAL_SCORE)
            .applauseRate(UPDATED_APPLAUSE_RATE)
            .updateTime(UPDATED_UPDATE_TIME);
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(updatedEvaluationData);

        restEvaluationDataMockMvc.perform(put("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isOk());

        // Validate the EvaluationData in the database
        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeUpdate);
        EvaluationData testEvaluationData = evaluationDataList.get(evaluationDataList.size() - 1);
        assertThat(testEvaluationData.getTemplateId()).isEqualTo(UPDATED_TEMPLATE_ID);
        assertThat(testEvaluationData.getOriginType()).isEqualTo(UPDATED_ORIGIN_TYPE);
        assertThat(testEvaluationData.getTotalScore()).isEqualTo(UPDATED_TOTAL_SCORE);
        assertThat(testEvaluationData.getApplauseRate()).isEqualTo(UPDATED_APPLAUSE_RATE);
        assertThat(testEvaluationData.getUpdateTime()).isEqualTo(UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void updateNonExistingEvaluationData() throws Exception {
        int databaseSizeBeforeUpdate = evaluationDataRepository.findAll().size();

        // Create the EvaluationData
        EvaluationDataDTO evaluationDataDTO = evaluationDataMapper.toDto(evaluationData);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restEvaluationDataMockMvc.perform(put("/api/evaluation-data").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(evaluationDataDTO)))
            .andExpect(status().isBadRequest());

        // Validate the EvaluationData in the database
        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteEvaluationData() throws Exception {
        // Initialize the database
        evaluationDataRepository.saveAndFlush(evaluationData);

        int databaseSizeBeforeDelete = evaluationDataRepository.findAll().size();

        // Delete the evaluationData
        restEvaluationDataMockMvc.perform(delete("/api/evaluation-data/{id}", evaluationData.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<EvaluationData> evaluationDataList = evaluationDataRepository.findAll();
        assertThat(evaluationDataList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
